home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / Inspector.m < prev    next >
Encoding:
Text File  |  1992-04-25  |  8.0 KB  |  327 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Inspector.h"
  5.  
  6. #import "HDraw.h"
  7. #import "Graphic.h"
  8. #import "GraphicView.h"
  9. #import "DrawDocument.h"
  10. #import <appkit/Application.h>
  11. #import <appkit/Button.h>
  12. #import <appkit/Form.h>
  13. #import <appkit/NXColorWell.h>
  14. #import <appkit/NXColorPanel.h>
  15. #import <appkit/PopUpList.h>
  16. #import <appkit/Slider.h>
  17. #import <appkit/Text.h>
  18. #import <stdlib.h>
  19. #import <math.h> 
  20. #import <appkit/color.h>
  21.  
  22. @implementation Inspector
  23.  
  24. - reloadGraphic:graphic
  25. /*
  26.  * Loads up the size fields if they have changed since last time
  27.  * we loaded up the panel with this graphic.  This is used since we
  28.  * know that none of the things controlled by the InspectorPanel can
  29.  * change except the size from event to event.
  30.  */
  31. {
  32.     NXRect bounds;
  33.  
  34.     if (!graphic) return self;
  35.     [graphic getBounds:&bounds];
  36.     if (lastSize.width != bounds.size.width) {
  37.     [width setFloatValue:bounds.size.width];
  38.     lastSize.width = bounds.size.width;
  39.     }
  40.     if (lastSize.height != bounds.size.height) {
  41.     [height setFloatValue:bounds.size.height];
  42.     lastSize.height = bounds.size.height;
  43.     }
  44.  
  45.     return self;
  46. }
  47.  
  48. static void setTitle(id button, int row)
  49. {
  50.     [button setTitle:[[[[button target] itemList] cellAt:row :0] title]];
  51. }
  52.  
  53. - preset
  54. {
  55.     [fillColor setColor:NX_COLORCLEAR];
  56.     [lineColor setColor:NX_COLORBLACK];
  57.     [textColor setColor:NX_COLORCLEAR];
  58.     return self;
  59. }
  60.  
  61. - loadGraphic:graphic
  62. /*
  63.  * Loads up the InspectorPanel with a new graphic's attributes.
  64.  */
  65. {
  66.     NXRect bounds;
  67.  
  68.     if (selectedGraphic == graphic) return [self reloadGraphic:graphic];
  69.     selectedGraphic = graphic;
  70.     if (!selectedGraphic) return self;
  71.  
  72.     [lineWidthField setFloatValue:[graphic lineWidth]];
  73.     [lineWidthSlider setFloatValue:[graphic lineWidth]];
  74.     [lineColor setColor:[graphic lineColor]];
  75.     [fillColor setColor:[graphic fillColor]];
  76.     [textColor setColor:[graphic textColor]];
  77.     [graphic getBounds:&bounds];
  78.     [width setFloatValue:bounds.size.width];
  79.     [height setFloatValue:bounds.size.height];
  80.     lastSize = bounds.size;
  81.     if ([graphic fill]) {
  82.     [filled setEnabled:YES];
  83.     setTitle(filled, [graphic fill]);
  84.     } else {
  85.     setTitle(filled, 0);
  86.     [filled setEnabled:NO];
  87.     }
  88.     setTitle(lineCap, [graphic lineCap]);
  89.     setTitle(arrows, [graphic lineArrow]);
  90.     setTitle(lineJoin, [graphic lineJoin]);
  91.     if ([graphic wantsLineColor]) {
  92.     [lineColor activate:YES];
  93.     if (NXEqualColor([lineColor color], [graphic fillColor])) [fillColor activate:NO];
  94.     } else if ([graphic wantsFillColor]) {
  95.     [fillColor activate:YES];
  96.     if (NXEqualColor([fillColor color], [graphic lineColor])) [lineColor activate:NO];
  97.     } else if ([graphic wantsTextColor]) {
  98.     [textColor activate:YES];
  99.     }
  100.  
  101.     return self;
  102. }
  103.  
  104. - load:view
  105. /*
  106.  * If the view has only one selected graphic, then the panel is loaded with it.
  107.  */
  108. {
  109.     graphicView = view;
  110.     [self loadGraphic:[view selectedGraphic]];
  111.     return self;
  112. }
  113.  
  114. - initializeGraphic:graphic
  115. /*
  116.  * Goes the opposite way of loadGraphic.  Gives the Graphic the attributes
  117.  * which are in the InspectorPanel.
  118.  */
  119. {
  120.     float value;
  121.     const char *s;
  122.     NXColor color;
  123.  
  124.     s = [lineWidthField stringValue];
  125.     if (s && s[0] && (value = atof(s))) [graphic setLineWidth:&value];
  126.     color = [lineColor color];
  127.     [graphic setLineColor:&color];
  128.     color = [fillColor color];
  129.     [graphic setFillColor:&color];
  130.     color = [textColor color];
  131.     if ([graphic wantsTextColor]) {
  132.     if (NXEqualColor(color, NX_COLORCLEAR)) {
  133.         color = NX_COLORBLACK;
  134.         [textColor setColor:color];
  135.     }
  136.     } else {
  137.     if (!NXEqualColor(color, NX_COLORCLEAR)) {
  138.         color = NX_COLORCLEAR;
  139.         [textColor setColor:color];
  140.     }
  141.     }
  142.     [graphic setGraphicTextColor:&color];
  143.     [graphic setFill:[[[filled target] itemList] selectedRow]];
  144.     [graphic setLineCap:[[[lineCap target] itemList] selectedRow]];
  145.     [graphic setLineArrow:[[[arrows target] itemList] selectedRow]];
  146.     [graphic setLineJoin:[[[lineJoin target] itemList] selectedRow]];
  147.     if ([graphic wantsLineColor]) {
  148.     [lineColor activate:YES];
  149.     if (NXEqualColor([lineColor color], [graphic fillColor])) [fillColor activate:NO];
  150.     } else if ([graphic wantsFillColor]) {
  151.     [fillColor activate:YES];
  152.     if (NXEqualColor([fillColor color], [graphic lineColor])) [lineColor activate:NO];
  153.     } else if ([graphic wantsTextColor]) {
  154.     [textColor activate:YES];
  155.     }
  156.  
  157.     return self;
  158. }
  159.  
  160. /* Overridden from superclass */
  161.  
  162. - windowDidUpdate:sender
  163. /*
  164.  * Called each time an event occurs.  Loads up the panel.
  165.  */
  166. {
  167.     if (hDraw == nil ) {
  168.         hDraw = NXGetNamedObject("HDrawInstance", NXApp);
  169.     }
  170.     [self load:[[hDraw currentDocument] view]];
  171.     return self;
  172. }
  173.  
  174. - changeContinuous:sender
  175. {
  176.     [[NXColorPanel sharedInstance:NO] setContinuous:([sender intValue] ? YES : NO)];
  177.     return self;
  178. }
  179.  
  180. /* Target/Action methods */
  181.  
  182. - changeFilled:sender
  183. {
  184.     [graphicView takeFillValueFrom:[[filled target] itemList]];
  185.     if ([[filled target] itemList] && ![[[filled target] itemList] selectedRow]) {
  186.     [fillColor deactivate];
  187.     [fillColor setColor:NX_COLORCLEAR];
  188.     [filled setEnabled:NO];
  189.     }
  190.     return self;
  191. }
  192.  
  193. - changeLineCap:sender
  194. {
  195.     [graphicView takeLineCapFrom:[[lineCap target] itemList]];
  196.     return self;
  197. }
  198.  
  199. - changeArrows:sender
  200. {
  201.     [graphicView takeLineArrowFrom:[[arrows target] itemList]];
  202.     return self;
  203. }
  204.  
  205. - changeLineJoin:sender
  206. {
  207.     [graphicView takeLineJoinFrom:[[lineJoin target] itemList]];
  208.     [[graphicView window] makeKeyWindow];
  209.     return self;
  210. }
  211.  
  212. - changeLineWidth:sender
  213. {
  214.     float linewidth;
  215.  
  216.     linewidth = [sender floatValue];
  217.     if (sender == lineWidthSlider) {
  218.     if ([NXApp currentEvent]->type == NX_MOUSEDRAGGED) {
  219.         [graphicView graphicsPerform:@selector(deselect) andDraw:NO];
  220.     } else {
  221.         [graphicView graphicsPerform:@selector(select) andDraw:NO];
  222.     }
  223.     [lineWidthField setFloatValue:linewidth];
  224.     } else {
  225.     if ([lineWidthSlider maxValue] < linewidth) {
  226.         [lineWidthSlider setMaxValue:linewidth];
  227.     }
  228.     [lineWidthSlider setFloatValue:linewidth];
  229.     [[graphicView window] makeKeyWindow];
  230.     }
  231.     [graphicView takeLineWidthFrom:lineWidthField];
  232.     return self;
  233. }
  234.  
  235. - changeTextColor:sender
  236. {
  237.     id fe;
  238.  
  239.     [graphicView takeTextColorFrom:sender];
  240.     fe = [[graphicView window] getFieldEditor:NO for:self];
  241.     [fe setSelColor:[sender color]];
  242.  
  243.     return self;
  244. }
  245.  
  246. - changeLineColor:sender
  247. {
  248.     [graphicView takeLineColorFrom:sender];
  249.     return self;
  250. }
  251.  
  252. - changeFillColor:sender
  253. {
  254.     [graphicView takeFillColorFrom:sender];
  255.     if (NXAlphaComponent([sender color]) == NX_NOALPHA ||
  256.     NXAlphaComponent([sender color]) == 1.0) {
  257.     [filled setEnabled:YES];
  258.     if (![[[filled target] itemList] selectedRow]) {
  259.         [[[filled target] itemList] selectCellAt:1 :0];
  260.         setTitle(filled, 1);
  261.         [self changeFilled:[filled target]];
  262.     }
  263.     } else {
  264.     if ([[[filled target] itemList] selectedRow]) {
  265.         [[[filled target] itemList] selectCellAt:0 :0];
  266.         setTitle(filled, 0);
  267.         [self changeFilled:[filled target]];
  268.     }
  269.     }
  270.     return self;
  271. }
  272.  
  273.  
  274. - changeDimensions:sender
  275. {
  276.     NXSize size;
  277.  
  278.     size.width = [width floatValue];
  279.     size.height = [height floatValue];
  280.     [graphicView graphicsPerform:@selector(sizeTo:) with:(id)&size andDraw:YES];
  281.     [[[graphicView window] flushWindow] makeKeyWindow];
  282.  
  283.     return self;
  284. }
  285.  
  286. - setFilled:anObject
  287. {
  288.     id matrix = [[anObject target] itemList];
  289.     [matrix setTarget:self];
  290.     [matrix setAction:@selector(changeFilled:)];
  291.     [matrix selectCellAt:0 :0];
  292.     filled = anObject;
  293.     return self;
  294. }
  295.  
  296. - setLineJoin:anObject
  297. {
  298.     id matrix = [[anObject target] itemList];
  299.     [matrix setTarget:self];
  300.     [matrix setAction:@selector(changeLineJoin:)];
  301.     [matrix selectCellAt:0 :0];
  302.     lineJoin = anObject;
  303.     return self;
  304. }
  305.  
  306. - setLineCap:anObject
  307. {
  308.     id matrix = [[anObject target] itemList];
  309.     [matrix setTarget:self];
  310.     [matrix setAction:@selector(changeLineCap:)];
  311.     [matrix selectCellAt:0 :0];
  312.     lineCap = anObject;
  313.     return self;
  314. }
  315.  
  316. - setArrows:anObject
  317. {
  318.     id matrix = [[anObject target] itemList];
  319.     [matrix setTarget:self];
  320.     [matrix setAction:@selector(changeArrows:)];
  321.     [matrix selectCellAt:0 :0];
  322.     arrows = anObject;
  323.     return self;
  324. }
  325.  
  326. @end
  327.